home *** CD-ROM | disk | FTP | other *** search
- property ancestor, p_parent, p_callback, p_callback_target, p_sprite_classes, p_sprites, p_animation_finished_count, p_sfx, p_sfx_time
-
- on new me, parent, callback, callback_target, sprite_classes, sfx, sfx_time
- me.p_parent = parent
- me.p_callback = callback
- me.p_callback_target = callback_target
- me.p_sprites = []
- me.p_sprite_classes = sprite_classes
- me.p_sfx = sfx
- me.p_sfx_time = sfx_time
- return me
- end
-
- on integrate me, delta_time
- call(#integrate, me.p_sprites, delta_time)
- end
-
- on start_sequence me
- me.p_animation_finished_count = 0
- sprite_states = me.get_initial_sprite_states()
- me.sequence(sprite_states)
- end
-
- on next_sequence me
- me.p_animation_finished_count = 0
- sprite_states = me.get_current_sprite_states()
- me.sequence(sprite_states)
- end
-
- on sequence me, sprite_states
- me.p_sprites = []
- i = 0
- if not voidp(me.p_sfx_time) then
- me.p_sfx_time = me.p_sfx_time - 1
- if me.p_sfx_time = 0 then
- sfx_play_sound(me.p_sfx)
- end if
- end if
- repeat with curr_state in sprite_states
- me.p_sprites.add(script(me.p_sprite_classes.getPropAt(1)).new(me, #animation_done, curr_state.image_name, curr_state.loc, curr_state.speed, me.p_sprite_classes[1] * i))
- i = i + 1
- end repeat
- me.p_sprite_classes.deleteAt(1)
- end
-
- on get_initial_sprite_states me
- sprite_states = []
- repeat with i = 1 to 7
- sprite_states.add([#image_name: "letter_r", #loc: point(0, 0), #speed: point(0, 0)])
- end repeat
- return sprite_states
- end
-
- on get_current_sprite_states me
- sprite_states = []
- repeat with curr_sprite in me.p_sprites
- sprite_states.add([#image_name: curr_sprite.p_img_name, #loc: curr_sprite.p_loc, #speed: curr_sprite.p_speed])
- end repeat
- return sprite_states
- end
-
- on animation_done me
- me.p_animation_finished_count = me.p_animation_finished_count + 1
- if me.p_animation_finished_count = me.p_sprites.count then
- if me.p_sprite_classes.count > 0 then
- me.next_sequence()
- else
- me.callback()
- end if
- end if
- end
-
- on callback me
- if objectp(me.p_callback_target) then
- if symbolp(me.p_callback) then
- call(me.p_callback, me.p_callback_target)
- end if
- end if
- end
-
- on draw_sprites me, buffer
- repeat with curr_sprite in p_sprites
- curr_loc = me.translate_loc(curr_sprite.p_loc, buffer)
- dest_rect = rect(curr_loc[1], curr_loc[2], curr_loc[1] + curr_sprite.p_src_img.width, curr_loc[2] + curr_sprite.p_src_img.height)
- buffer.copyPixels(curr_sprite.p_src_img, dest_rect, curr_sprite.p_src_img.rect, [#ink: 8, #matte: curr_sprite.p_matte])
- end repeat
- return buffer
- end
-
- on translate_loc me, rel_loc, buffer
- abs_loc = point(rel_loc[1] + (buffer.width / 2), rel_loc[2] + (buffer.height / 2))
- return abs_loc
- end
-
- on dispose me
- me.p_parent = VOID
- me.p_callback = VOID
- me.p_callback_target = VOID
- call(#dispose, me.p_sprites)
- me.p_sprites = VOID
- me.p_sprite_classes = VOID
- me.p_animation_finished_count = VOID
- me.p_sfx = VOID
- me.p_sfx_time = VOID
- callAncestor(#dispose, [me])
- end
-